function callback_function() {
    hljs.initHighlightingOnLoad();
}

$("#vimg").click(function(){
    $(this).attr("src",base_url + "/createCode.jspx?timer="+new Date().getTime());
}).mouseover(function(){
    $(this).css("cursor","pointer");
});

$("#email").blur(function(){
    var emailValue = this.value;
    if($.trim(emailValue) != ""){
        var reemail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if(!reemail.test(emailValue)){
            layer.msg("您输入的邮箱格式不正确,请重新输入!", {icon: 5, time: LayUIConstant.TIP_TIME});
            $("#email").focus();
            return;
        }
    }
});

$("#websiteUrl").blur(function(){
    var webValue = this.value;
    if($.trim(webValue) != ""){
        var reUrl=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
        if(!reUrl.test(webValue)){
            layer.msg("您输入的网址格式不正确,请重新输入!", {icon: 5, time: LayUIConstant.TIP_TIME});
            $("#websiteUrl").focus();
            return;
        }
    }
});

function subComment(){

    var articleId = $("#articleId").val();
    var nickname = $("#nickname").val();
    if($.trim(nickname) == ""){
        layer.msg("请输入名称!", {icon: 5, time: LayUIConstant.TIP_TIME});
        $("#nickname").focus();
        return;
    }
    var n = nickname.length;
    if(n>32){
    	 layer.msg("名称过长，请重新输入!", {icon: 5, time: LayUIConstant.TIP_TIME});
         $("#nickname").focus();
         return;
    }
    
    var email =$("#email").val();
    if($.trim(email) == ""){
        layer.msg("请输入邮箱!", {icon: 5, time: LayUIConstant.TIP_TIME});
        $("#email").focus();
        return;
    }
    var websiteUrl = $("#websiteUrl").val();

    var content = $("#content").val();
    if($.trim(content) == ""){
        layer.msg("请输入内容!", {icon: 5, time: LayUIConstant.TIP_TIME});
        $("#content").focus();
        return;
    }
    var code = $("#vcode").val();
    if($.trim(code) == ""){
        layer.msg("请输入验证码!", {icon: 5, time: LayUIConstant.TIP_TIME});
        $("#vcode").focus();
        return;
    }
    var params ={"articleId":articleId,"nickname":nickname,"email":email,"websiteUrl":websiteUrl,"content":content,"code":code};
    $.ajax({
        url:base_url + '/comment/subComment.jspx',
        data:params,
        type:'post',
        dataType:'json',
        success:function(data){
            if(data.code == 0){
                layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME});
                setTimeout(function () {
                    location.reload();
                }, 1500);
            }else{
                layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        },
        error:function(data){
            layer.msg("操作失败!", {icon: 5, time: LayUIConstant.TIP_TIME});
        }
    });
}